package com.example.testfullcalendar.service.impl;


import com.example.testfullcalendar.mapper.IndexDao;
import com.example.testfullcalendar.pojo.MyEvent;
import com.example.testfullcalendar.pojo.StatusColorEnum;
import com.example.testfullcalendar.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("indexServiceImpl")
public class IndexServiceImpl implements IndexService {

    private final IndexDao indexDao;
    @Autowired
    public IndexServiceImpl(IndexDao indexDao) {
        this.indexDao = indexDao;
    }

    @Override
    public void addMyEvent(MyEvent event) {
        indexDao.insertMyEvent(event);
    }

    @Override
    public List<MyEvent> findAllEventByTime(String startTime, String endTime) {
        List<MyEvent> eventList = indexDao.selectAllEventByTime(startTime, endTime);
        for (MyEvent myEvent : eventList) {
            myEvent.setEventStatus(StatusColorEnum.getColorById(Integer.parseInt(myEvent.getEventStatus())));
        }
        return eventList;
    }

    @Override
    public void modifyEventById(MyEvent myEvent) {
        indexDao.updateEventById(myEvent);
    }

    @Override
    public void removeEventById(MyEvent myEvent) {
        indexDao.deleteEventById(myEvent);
    }
}
